<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>{$title}</title>
    <link rel="stylesheet" type="text/css" href="//cdn.bilnn.top/js/aui/aui.2.0.css"/>
    <style>
        body{

        }
    </style>
</head>
<body>
<header class="aui-bar aui-bar-nav">
    {if $backurl}
    <a class="aui-pull-left aui-btn" onclick="window.location.href='{urldecode($backurl)}'">
        <span class="aui-iconfont aui-icon-left"></span>
    </a>
    {/if}
    <a class="aui-pull-right">
        {if $user}{$user.score}积分{/if}
    </a>
    <div class="aui-title"></div>
</header>
    <div class="aui-tab" id="tab">
        <div class="aui-tab-item {if $action=='index'}aui-active{/if}" style="z-index: 1;" onclick="window.location.href='?c=gift&a=index&backurl={$backurl}'">在线商城</div>
        <div class="aui-tab-item {if $action=='my_gift'}aui-active{/if}" style="z-index: 1;" onclick="window.location.href='?c=gift&a=my_gift&backurl={if !empty($smarty.get.backurl)}{urlencode($smarty.get.backurl)}{/if}'">我的背包</div>
        <div class="aui-tab-item {if $action=='my_gift_log'}aui-active{/if}" style="z-index: 1;" onclick="window.location.href='?c=gift&a=my_gift_log&backurl={if !empty($smarty.get.backurl)}{urlencode($smarty.get.backurl)}{/if}'">礼物记录</div>
    </div>

    <div class="aui-content aui-margin-b-15">
        {if $action=='index'}
        <section class="aui-grid aui-margin-b-15">
            <h3 class="aui-text-info aui-margin-l-15 aui-margin-t-15">当前积分：{$user.score}<span style="font-size: 0.7rem;color: #757575;">（10积分=1元）</span><div class="aui-btn aui-btn-success" onclick="recharge()">立即充值</div></h3>
            <p class="aui-margin-l-15 " style="font-size: 0.7rem;color: #757575;">1.礼物可以打赏给喜欢的文件分享<br>2.上传者将获得礼物的9折分成(可提现)</p>
            <div class="aui-row" >
                {foreach from=$gift item=one}
                <div class="aui-col-xs-4">
                    <p><img src="/app{$one.gift_pic}" style="width: 4rem;"></p>
                    <p>{$one.gift_price}积分</p>
                    <div class="aui-grid-label">{$one.gift_name}</div>
                    <div class="aui-btn aui-btn-warning" style="margin-top: 0.3rem" onclick="buy_gift({$one.id})">购买</div>
                </div>   
                {/foreach}
            </div>

        </section>
        {/if}
        {if $action=='my_gift'}
        <section class="aui-grid aui-margin-b-15">
            <p class="aui-margin-l-15 " style="font-size: 0.7rem;color: #757575;">1.礼物可以打赏给喜欢的文件分享<br>2.上传者将获得礼物的9折分成(可提现)</p>
            <div class="aui-row" >
                {if $gift}
                {foreach from=$gift item=one}
                <div class="aui-col-xs-4">
                    <p><img src="/app{$one.gift_pic}" style="width: 4rem;"></p>
                    <p>{$one.gift_price}积分</p>
                    <div class="aui-grid-label">{$one.gift_name}*{$one.gift_num}</div>
                </div>   
                {/foreach}
                {else}
                <p class="aui-margin-b-15 aui-margin-t-15" style="text-align: center;"><a href="?c=game&a=duobao">【还没有礼物，去玩游戏获得】</a></p>
                {/if}
            </div>

        </section>
        {/if}
        {if $action=='my_gift_log'}
        <section class="aui-grid aui-margin-b-15">
            <p class="aui-margin-l-15 " style="font-size: 0.7rem;color: #757575;">1.礼物可以打赏给喜欢的文件分享<br>2.上传者将获得礼物的9折分成(可提现)</p>
            <ul class="aui-list aui-media-list">
                <li class="aui-list-header">礼物记录</li>
                {foreach from=$gift item=one}
                <li class="aui-list-item">
                    <div class="aui-media-list-item-inner">
                        <div class="aui-list-item-inner">
                            <div class="aui-card-list-user-avatar">
                                <img src="/app{$one.gift_pic}">
                            </div>
                            <div class="aui-list-item-text">
                                <div class="aui-list-item-title">{$one.gift_name}&nbsp;<span class="aui-text-primary">{if $one.gift_num>0}+{/if}{$one.gift_num}</span></div>
                                <div class="aui-list-item-right">{if $one.gift_num>0}<span class="aui-text-success">[增加]{else}<span class="aui-text-danger">[减少]{/if}</span>&nbsp;{$one.ctime}</div>
                            </div>
                            <div class="aui-list-item-text aui-ellipsis-2">
                            {$one.title}
                            </div>
                        </div>
                    </div>
                </li>
                {/foreach}
            </ul>
            <h3><div class="aui-pager" style="margin-left:0rem;margin-right:0rem"></div></h3>
        </section>
        {/if}
    </div>
</div>
</body>
<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdn.bilnn.top/js/aui/aui-dialog.js"></script>
<script src="//cdn.bilnn.top/js/aui/aui-toast.js"></script>
<script src="View/js/fun.js"></script>
<script src="//cdn.bilnn.top/js/aui/jquery.pagination.js"></script>
<script>
    {if !empty($pager)}
    $('.aui-pager').pagination({
        totalData:{if $pager.total==0}1{else}{$pager.total}{/if},
        showData:{$pager.limit},
        current:{$pager.now},
        count:4,
        mode:'fixed',
        prevContent: '上页',
        nextContent: '下页',
        callback:function(e){
            var urls = window.location.href;
            if (urls.indexOf("page=")==-1){
                if (urls.indexOf("?")==-1){
                    urls = urls+"?page="+e.getCurrent();
                }else{
                    urls = urls+"&page="+e.getCurrent();
                }
            }else{
                urls = urls.split("page=");
                urls = urls[0];
                urls = urls+"page="+e.getCurrent();
            }
            window.location.href = urls;
        }
    });
    {/if}
    
    function buy_gift(gift_id) {
        var dialog = new auiDialog();
        var toast = new auiToast();
        dialog.prompt({
            title:"购买数量",
            text:'请输入购买数量',
            intval:true,
            value:"1",
            buttons:['取消','确定']
        },function(ret){
            if(ret.buttonIndex == 2){
                if (ret.text==''){
                    toast.fail({
                        title:"购买数量为空",
                        duration:2000
                    });
                }else{
                    var back = vpost("?c=gift&a=buy","gift_id="+gift_id+"&num="+ret.text);
                    if (back.code==0){
                        malert("提示：","购买成功",1);
                    }else{
                        toast.fail({
                        title:back.msg,
                        duration:2000
                    });
                    }
                } 
            }
        })
    }

    function recharge() {
        var dialog = new auiDialog();
        var toast = new auiToast();
        dialog.prompt({
            title:"充值积分",
            text:'请输入积分，10积分=1元',
            intval:true,
            value:"10",
            html:'<div class="aui-content aui-margin-t-15"><input class="aui-radio" type="radio" name="pay_id" checked style="height:1.2rem;min-height:1.2rem" value="alipay"> 支付宝支付&nbsp;&nbsp;&nbsp;&nbsp;<input class="aui-radio" type="radio" name="pay_id" style="height:1.2rem;min-height:1.2rem" value="wechat"> 微信支付</div>',
            buttons:['取消','确定']
        },function(ret){
            if(ret.buttonIndex == 2){
                if (ret.text==''){
                    toast.fail({
                        title:"充值金额为空",
                        duration:2000
                    });
                }else{
                    var back = vposts("/api/v3/vas/order",JSON.stringify({ action: "score",method:$("input[name='pay_id']:checked").val(),id:1,num:parseInt(ret.text)}));
                    if (back.code==0){
                        dialog.alert({
                            title:"扫码支付",
                            msg:'支付完成后刷新页面<br><img width="128" src="https://api.pwmqr.com/qrcode/create/?url='+encodeURIComponent(back.data.qr_code)+'">',
                            buttons:['确定']
                        },function(ret){
                            window.location.reload();
                        })
                    }else{
                        toast.fail({
                        title:back.msg,
                        duration:2000
                    });
                    }
                } 
            }
        })
    }
</script>
</html>